import { defineStore } from "pinia"
const useAction = defineStore("action", {
    state: () => ({
        money: 100,
        banners: [],
        recommends: [],
    }),
    actions: {
        addMoney() {
            this.money++
        },
        addMoneyNum(state) {
            this.money += state
        },
        async fetchActionMultidata() {
            // const res = await fetch("http://123.207.32.32:8000/home/multidata")
            // const data = await res.json()
            // console.log(data)

            // this.banners = data.data.banner.list
            // this.recommends = data.data.recommend.list

            // 返回 promise写法
            return new Promise(async (resolve, reject) => {
                const res = await fetch("http://123.207.32.32:8000/home/multidata")
                const data = await res.json()
                console.log(data)

                this.banners = data.data.banner.list
                this.recommends = data.data.recommend.list

                resolve("haha")
            })
        }
    }
})
export default useAction